# Image used only for build process
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY ./src/Kubeless.Core/*.csproj ./Kubeless.Core/
COPY ./src/Kubeless.Functions/*.csproj ./Kubeless.Functions/
COPY ./src/Kubeless.WebAPI/*.csproj ./Kubeless.WebAPI/
RUN dotnet restore ./Kubeless.WebAPI/

# Copy everything else and build in release mode
COPY ./src/ ./
RUN dotnet publish ./Kubeless.WebAPI/ -c Release -o Kubeless.WebAPI/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/Kubeless.WebAPI/out .
# Kubeless.Functions reference
COPY --from=build-env /app/Kubeless.WebAPI/out/Kubeless.Functions.dll /usr/share/dotnet/store/x64/netcoreapp2.0/.

RUN chown 1000 /app
COPY ./run-webapi.sh ./
RUN chmod +x ./run-webapi.sh

ENTRYPOINT ["/app/run-webapi.sh"]